package net.wofly;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Created by LiuJianbo on 2017/10/2.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    
    @Bean
    public Docket createRestApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("test")
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(true)
                .pathMapping("/")// base，最终调用接口后会和paths拼接在一起
                .select()
                .paths(Predicates.or(PathSelectors.regex("/api/.*")))//过滤的接口
                .build()
                .apiInfo(testApiInfo());
        ;
        return docket;
    }
    
    private ApiInfo testApiInfo() {
        ApiInfo apiInfo = new ApiInfo("Sale后台服务接口",//大标题
                "Sale后台服务接口.",//小标题
                "1.0",//版本
                "",
                "XinHai",//作者
                "鑫海飞扬",//链接显示文字
                "http://www.xinhaifeiyang.com/"//网站链接
        );
        
        return apiInfo;
    }
    
}
